//
//  ZJKStatus.swift
//  MicroBlog
//
//  Created by VAD on 16/4/20.
//  Copyright © 2016年 朱江坤. All rights reserved.
//

import UIKit

class ZJKStatus: NSObject {
    
    var id: Int64 = 0
    //当前微博的内容
    var text: String?
    /// 微博的创建时间
    var created_at: String?
    /// 来源
    var source: String?
    /// 当前微博的用户信息
    var user: ZJKUser?
    /// 当前微博转发微博，因为其内部字段与 ZJKStatus 一样，所以就设置其类型为 ZJKStatu
    var retweeted_status: ZJKStatus?
    /// 配图数组
    var pic_urls: [ZJKStatusPhotoInfo]?

    
    init(dict: [String: AnyObject]){
        super.init()
        
        setValuesForKeysWithDictionary(dict)
        
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            // 自已手动字典转模型？
            guard let dict = value as? [String: AnyObject] else{
                return
            }
            user = ZJKUser(dict: dict)
        }else if key == "retweeted_status" {
            // 手动转转发微博
            guard let dict = value as? [String: AnyObject] else {
                return
            }
            retweeted_status = ZJKStatus(dict: dict)
        }else if key == "pic_urls"{
            
            guard let dicts = value as? [[String: AnyObject]] else {
                return
            }
            var tempArray = [ZJKStatusPhotoInfo]()
            
            for dict in dicts {
                
                let info = ZJKStatusPhotoInfo(dict: dict)
                
                tempArray.append(info)
            }
            pic_urls = tempArray
            
        }else{
            
            super.setValue(value, forKey: key)
        }
    }

    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }

}
